package pl.wr.physics.units.quantum.particleflavour.related;

import pl.wr.math.Sign;
import pl.wr.math.number.Fraction;
import pl.wr.physics.units.Constants;
import pl.wr.physics.units.SI.derived.C;
import pl.wr.physics.units.quantum.QuantumUnit;

/**
 * In quantum mechanics and particle physics, spin is a fundamental
 * characteristic property of elementary particles, composite particles
 * (hadrons), and atomic nuclei. The spin quantum number is a quantum number
 * that parameterizes the intrinsic angular momentum (or spin angular momentum,
 * or simply spin) of a given particle.
 * 
 * @version 1.0
 * @author wieslaw.rodak
 * 
 */
public final class ElectricCharge implements QuantumUnit {

    public final Fraction charge;

    /** A charge representing "0". */
    public static final ElectricCharge ZERO = new ElectricCharge(Fraction.ZERO);

    /** A charge representing "+1 e". */
    public static final ElectricCharge ONE = new ElectricCharge(Fraction.ONE);

    /** A charge representing "-1 e". */
    public static final ElectricCharge MINUS_ONE = new ElectricCharge(Fraction.MINUS_ONE);

    /** A charge representing "-1/3 e". */
    public static final ElectricCharge MINUS_ONE_THIRD = new ElectricCharge(Fraction.MINUS_ONE_THIRD);

    /** A charge representing "+2/3 e". */
    public static final ElectricCharge TWO_THIRDS = new ElectricCharge(Fraction.TWO_THIRDS);

    /** A charge representing "+1/3 e". */
    public static final ElectricCharge ONE_THIRD = new ElectricCharge(Fraction.ONE_THIRD);

    /** A charge representing "-2/3 e". */
    public static final ElectricCharge MINUS_TWO_THIRDS = new ElectricCharge(Fraction.MINUS_TWO_THIRDS);

    private ElectricCharge(Fraction value) {
        charge = value;
    }

    /**
     * @param s
     *            The sign of value.
     * @param multiply
     *            The multiply value of 1/3.
     */
    public ElectricCharge(Sign s, int multiply) {
        switch (s) {
        case minus:
            multiply = -multiply;
        }
        charge = new Fraction(multiply, 3);
    }

    @Override
    public C getSIValue() {
        return new C(Fraction.multiply(charge, Constants.e.getValue()));
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(32);
        builder.append("ElectricCharge [charge=").append(charge).append(']');
        return builder.toString();
    }

}
